package com.example.demo.pattern.iteratorpattern;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 准确的说应该是MenuList，这是一个菜单文件夹
 */
public class Menu extends MenuComponent {
    //内部包含一个ArrayList
    private final ArrayList<MenuComponent> menuList = new ArrayList<MenuComponent>();

    public Menu(String name) {
        this.name = name;
    }

    @Override
    public void addMenu(MenuComponent menuComponent) {
        menuList.add(menuComponent);
    }

    @Override
    protected void print() {
        System.out.println("list-" + this.name);
    }

    @Override
    protected Iterator<MenuComponent> iterator() {
        return menuList.iterator();
    }
}
